<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <button onclick="testObj()">测试</button>

    <script>
        //声明Student构造函数
         function Student(stuId,stuName,stuAge){
            //对象中的属性
           this.stuId = stuId;
           this.stuName = stuName;
           this.stuAge = stuAge;     
        }
        function testObj(){
            //Student.stuSex="男";//错误，Student不是一个具体对象无法直接设置属性
            //使用对象的原型属性为该类对象设置共享属性
            Student.prototype.stuSex = "男";

            let student = new Student(1003,"强哥",22);
            //student.stuSex = "男";//为student对象设置一个属性
            console.log(student);
            console.log(student.stuSex);

            let student1 = new Student(1006,"小王",20);
            console.log(student1);
            student1.stuSex = "女";
            console.log(student1.stuSex);
        }
    </script>
</body>
</html>